//
//  LGCultureVideoCollectionView.m
//  ligenyun
//
//  Created by Mac on 2018/3/28.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGCultureVideoCollectionView.h"
#define itemWith 110
#define itemHeight 80
@interface LGCultureVideoCollectionView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic, strong) UICollectionView                     *collectionView;
@end
@implementation LGCultureVideoCollectionView

+ (LGCultureVideoCollectionView *)initWithDefultFrame{
    LGCultureVideoCollectionView * view = [[LGCultureVideoCollectionView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    UICollectionViewFlowLayout * flow = [UICollectionViewFlowLayout new];
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flow.minimumLineSpacing = 10;
    flow.minimumInteritemSpacing = 10;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(15, 10, UIScreenWidth - 30, 80) collectionViewLayout:flow];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerClass:[LGCultureVideoCollectionViewCell class] forCellWithReuseIdentifier:@"item"];
    [self addSubview:self.collectionView];
}
#pragma --mark UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20   ;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(itemWith, itemHeight);
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LGCultureVideoCollectionViewCell * item =[collectionView dequeueReusableCellWithReuseIdentifier:@"item" forIndexPath:indexPath];
    __weak typeof(self) weakSelf =  self;
    [item.banerIconButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedButton) {
            weakSelf.onSelectedButton(nil);
        }
    }];
    return item;
}
#pragma --mark UICollectionViewDelegate
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
}
@end

@interface LGCultureVideoCollectionViewCell()
@property(nonatomic, strong) UIImageView                     *playImageView;

@end
@implementation LGCultureVideoCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    
    self.banerIconButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, itemWith, itemHeight)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"宗祠风貌02"]];
    [self addSubview:self.banerIconButton];
    
    self.playImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
    self.playImageView.image = [UIImage imageNamed:@"播放拷贝"];
    [self addSubview:self.playImageView];
    self.playImageView.center = self.banerIconButton.center;
                          
}
@end
